#! /usr/bin/python3
# Author: <NAME>
# Date: 2025年3月10日09:25:03
# Description: 清除系统自带OpenSSH及备份文件
import os
import sys


class Clean:
    def __init__(self):
        self.p = "/usr/local/.ssh"
        self.src = "/etc/ssh"

    def uninstall(self):
        if not os.path.isdir(self.src):
            os.mkdir(self.src)
        if os.system("apt-get purge openssh-server -y") != 0:
            print("卸载openssh-server失败")
            sys.exit(1)

    def rm(self):
        if os.system("rm -rf %s" % self.p) != 0:
            print("删除%s失败" % self.p)
        # os.system("rm -rf /etc/ssh-guardian/config.toml")
        os.system("rm -rf /etc/ssh")

    def install(self):
        if os.system("apt-get install openssh-server -y") != 0:
            print("安装openssh-server失败")

    def run(self):
        if os.system("go build") != 0:
            print("编译ssh-guardian失败")
        os.system("./ssh-guardian -debug -sec 1 -lang zh")

    def start(self):
        self.uninstall()
        self.rm()
        self.install()
        self.run()


if __name__ == "__main__":
    c = Clean()
    c.start()
